﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
    <title></title>
</head>
<body>
</body>
<script type="text/javascript">
        var token;
        //获取到token的值保存到数据库(进入页面就执行)
        $(document).ready(function() { 
            $.ajax({
                type: "GET",
                async: false,
                data: {},
                url: "https://receive.symacnc.cn/v20/Verification/authorize?grant_type=clientc_credential&appid=11E96964685A7AAAB96598039B073FBC&secret=EV72BU9X2ZPV35XBR60HCWXBOUFRKTGMDJJAB3QZ&comid=11E8D1D6-636B-84CE-8CF1-00163E008027",
                dataType: "json", 
                success: function (ret) {
                    token = ret.access_token
                    $.ajax({
                        type: "GET",
                        async: false,
                        data: {token:token,method:'savetoken' },
                        url: "GetDeviceInfo.ashx",
                        dataType: "json",
                        success: function (ret) {

                        }
                    })
                }
            })
        });
        //获取在线设备信息
        $(document).ready(function() { 
            var t;
            var tokens;
            var urls = "https://receive.symacnc.cn/v20/Report/getStatuCount?grant_type=clientc_credential&access_token=";
             $.ajax({
                type: "GET",
                async: false,
                data:{method:'querytoken'},
                url: "GetDeviceInfo.ashx",
                dataType: "json",
                success: function (ret) {
                    tokens = ret.token;
                        $.ajax({
                            type: "GET",
                            async: false,
                            data: {},
                            url: "" + urls + tokens + "",
                            dataType: "json",
                            success: function (ret) {
                                var a_data = {};
                                var data = ret.data;
                                for (var i in data) {
                                    var a = data[i];
                                    a_data["name"] = a.name;
                                    a_data["value"] = a.value;
                                    t = a_data;
                                    //将数组解析为json格式传入后台
                                    var devicestate = JSON.stringify(t);
                                    $.ajax({
                                            type: "GET",
                                            async: false,
                                            data: { devicestate: devicestate, method:'savestate'},
                                            url: "GetDeviceInfo.ashx",
                                            dataType: "json",
                                            success: function (ret) {
                                        
                                            }
                                        })
                                }
                            }
                        })
                    }               
            })
        });
</script>
</html>
